package edu.gdkm.dao;

import edu.gdkm.pojo.Resume;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ResumeDao {

    // 根据ID查询
    @Select("SELECT * FROM Resumes WHERE resume_id = #{resumeId}")
    Resume selectById(Integer resumeId);

    // 查询所有简历
    @Select("SELECT * FROM Resumes")
    List<Resume> selectAll();

    // 根据用户ID查询简历
    @Select("SELECT * FROM Resumes WHERE user_id = #{userId}")
    List<Resume> selectByUserId(Integer userId);

    // 新增简历
    @Insert("INSERT INTO Resumes(user_id, template_id, title, description, is_default, created_at, updated_at, last_exported_at) " +
            "VALUES(#{userId}, #{templateId}, #{title}, #{description}, #{isDefault}, #{createdAt}, #{updatedAt}, #{lastExportedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "resumeId")
    int insert(Resume resume);

    // 更新简历
    @Update("UPDATE Resumes SET user_id = #{userId}, template_id = #{templateId}, title = #{title}, " +
            "description = #{description}, is_default = #{isDefault}, updated_at = #{updatedAt}, " +
            "last_exported_at = #{lastExportedAt} WHERE resume_id = #{resumeId}")
    int update(Resume resume);

    // 删除简历
    @Delete("DELETE FROM Resumes WHERE resume_id = #{resumeId}")
    int delete(Integer resumeId);
}
    